home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / CW GUSI 1.6.4 / src / GUSINull.cp < prev    next >
Text File  |  1995-08-25  |  2KB  |  78 lines

  1. /*********************************************************************
  2. Project    :    GUSI                -    Grand unified socket interface
  3. File        :    GUSINull.cp        -    Null Sockets
  4. Author    :    Matthias Neeracher
  5. Language    :    MPW C/C++
  6.  
  7. $Log$
  8. *********************************************************************/
  9.  
  10. #include <GUSIFile_P.h>
  11.  
  12. #include <TextUtils.h>
  13.  
  14. /************************ NullSocket members ************************/
  15.  
  16. class NullSocket : public Socket {
  17.     friend class NullSocketDomain;
  18. protected:
  19.     NullSocket();
  20. public:
  21.     virtual int    read(void * buffer, int buflen);
  22.     virtual int write(void * buffer, int buflen);
  23.     virtual int select(Boolean * canRead, Boolean * canWrite, Boolean * exception);
  24. };
  25.  
  26. /************************ NullSocket members ************************/
  27.  
  28. NullSocket::NullSocket()
  29. {
  30. }
  31.  
  32. int NullSocket::read(void *, int)
  33. {
  34.     return 0;
  35. }
  36.  
  37. int NullSocket::write(void *, int)
  38. {
  39.     return 0;
  40. }
  41.  
  42. int NullSocket::select(Boolean * canRead, Boolean * canWrite, Boolean * exception)
  43. {
  44.     int        goodies     =     0;
  45.     
  46.     if (canRead) {
  47.         *canRead = true;
  48.         ++goodies;
  49.     }
  50.     
  51.     if (canWrite) {
  52.         *canWrite = true;
  53.         ++goodies;
  54.     }
  55.     
  56.     if (exception)
  57.         *exception = false;
  58.     
  59.     return goodies;
  60. }
  61.  
  62. /********************* NullSocketDomain members **********************/
  63.  
  64. Boolean NullSocketDomain::Yours(const GUSIFileRef & ref, FileSocketDomain::Request request)
  65. {
  66.     return !ref.spec && (request == willOpen || request == willStat) 
  67.         && equalstring((char *) ref.name, "dev:null", false, true);
  68. }
  69.  
  70. Socket * NullSocketDomain::open(const GUSIFileRef & ref, int flags)
  71. {
  72.     if (!singleton)
  73.         singleton = new NullSocket();
  74.     ++*singleton;
  75.     
  76.     return singleton;
  77. }
  78.